@extends('app')
@include('UEditor::head')
@section('content')
<link rel="stylesheet" href="{{asset('/addons/kindeditor/themes/default/default.css')}}" />
<link rel="stylesheet" href="{{asset('/addons/kindeditor/plugins/code/prettify.css')}}" />
<script src="{{asset('/addons/kindeditor/kindeditor.js')}}" type="text/javascript"></script>
<script src="{{asset('/addons/kindeditor/lang/zh_CN.js')}}" type="text/javascript"></script>
<script src="{{asset('/addons/kindeditor/plugins/code/prettify.js')}}" type="text/javascript"></script>
<script type="text/javascript">
<!--
editorInit();
//-->
</script>
<ul class="nav nav-tabs">
    <li><a href="{{ url('/admin/employ/index')}}">信息列表</a></li>
    <li><a href="{{ url('/admin/employ/index/create') }}">信息添加</a></li>
    <li  class="active"><a href="{{ url('/admin/employ/index/create?template=1') }}">特殊模版</a></li>
</ul>
  <form id="newsForm" method="post" action="">
    <div class="panel panel-default description2">
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章标题</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" class="form-control" name="title" id="title" placeholder="标题" value="@if(!empty($result)){{ $result->title }}@endif">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章系列</label>
            <div class="col-sm-9 col-xs-12">
                <input type="text" class="form-control" name="to_link" id="to_link" placeholder="文章系列名称 无则不填写" value="@if(!empty($result)){{ $result->to_link }}@endif">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章分类</label>
            <div class="col-sm-3 col-xs-12" id="parent">
                <select name="type" class="form-control" id="type" onchange="getChilds('category',this.value,'parent')">
                    <option value="0">请选择分类</option>
                    @foreach($type as $tp)
                    <option value="{{ $tp->cat_id }}" @if(!empty($result)) @if(in_array($tp->cat_id,$categorys['id'])) selected @endif @elseif($nowtype == $tp->cat_id) selected @endif>{{ $tp->cat_name }}</option>
                    @endforeach
                </select>
                @if(empty($result))
                <script type="text/javascript">
				$(function(){
					getChilds('category','{{$nowtype}}','parent');
				});
                </script>
                @endif
            </div>
            @if(!empty($result))
                @if($item != 5)
                @foreach($categorys['list'] as $k=>$cglist)
                    <div class="col-sm-3 col-xs-12" id="child_{{$k-$item}}">
                        <select name="child_{{ $k-$item }}" class="form-control" id="child" onchange="getChilds(this.value,'child_{{ $k-$item }}')">
                    		<option value="0">请选择分类</option>
                    		@foreach($cglist as $cgl)
                    		<option value="{{ $cgl->cat_id }}" @if(in_array($cgl->cat_id,$categorys['id'])) selected @endif>{{ $cgl->cat_name }}</option>
                    		@endforeach
                    	</select>
                    </div>
                @endforeach
                @endif
                @if($item ==5)
                <div class="col-sm-3 col-xs-12" id="child_1"></div>
                <div class="col-sm-3 col-xs-12" id="child_2"></div>
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @elseif($item==4)
                <div class="col-sm-3 col-xs-12" id="child_2"></div>
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @elseif($item == 3)
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @endif
            @else
            <div class="col-sm-3 col-xs-12" id="child_1"></div>
            <div class="col-sm-3 col-xs-12" id="child_2"></div>
            <div class="col-sm-3 col-xs-12" id="child_3"></div>
            @endif
        </div> 
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章封面</label>
            <div class="col-sm-9 col-xs-12">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                <div id="imgbox" class="dustbin">
                    <div style='width:90px; height:60px;float:left;'>
                        <img src='@if(!empty($result)) {{ count($result->attachment)>0?$result->attachment->url:'' }} @endif' /><input type='hidden' name='thumb' value='@if(!empty($result)){{ $result->thumb }}@endif' />
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章简介:</label>
            <div class="col-sm-9 col-xs-12">
                <textarea rows="3" class="form-control" name="description" cols="5">@if(!empty($result)) {{strip_tags($result->description)}} @endif</textarea>
            </div>
        </div>
        <div id="content_layout">
            @if(empty($result))
            <div class="form-group can-del clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章内容:</label>
                <div class="col-sm-3 col-xs-12"><input type="text" class="form-control" name="content_title[]" value="" placeholder="左边标题"></div>
                <div class="col-sm-6 col-xs-12"><textarea class="form-control content" name="content_content[]" placeholder="内容"></textarea></div>
            </div>
            @else
            @foreach($result->content as $key=>$rcon)
            <div class="form-group can-del clearfix">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">@if($key == 0)文章内容:@endif</label>
                <div class="col-sm-3 col-xs-12"><input type="text" class="form-control" name="content_title[]" value="{{$rcon['title']}}" placeholder="左边标题"></div>
                <div class="col-sm-6 col-xs-12"><textarea class="form-control content" name="content_content[]" placeholder="内容">{!!$rcon['content']!!}</textarea></div>
                @if($key > 0)<a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>@endif
            </div>
            @endforeach
            @endif
        </div>
        <div class="form-group clearfix">
            <div class="col-xs-12 col-sm-3 col-md-2 control-label"></div>
            <div class="col-sm-3 col-xs-12">
                <button type="button" class="btn btn-default btn-block" name="employadd" id="employadd"><i class="glyphicon glyphicon-plus"></i>添加方法/步骤</button>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">相关标签:</label>
            <div class="col-sm-9 col-xs-12">
                <div class="tagsinput-primary">
                    <input name="tagsinput" class="tagsinput" data-role="tagsinput" value="@if(!empty($newstag)) {{ $newstag }} @endif" />
                </div>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章来源:</label>
            <div class="col-sm-3 col-xs-12">
                  <input type="text" class="form-control" name="from" placeholder="文章来源" value="@if(!empty($result)){{ $result->from }}@endif">
            </div>
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">原创作者:</label>
            <div class="col-sm-3 col-xs-12">
                  <input type="text" class="form-control" name="author" placeholder="原创作者" value="@if(!empty($result)){{ $result->author }}@endif">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章排序:</label>
            <div class="col-sm-9 col-xs-12">
                  <input type="text" class="form-control" name="sort" id="sort" value="@if(!empty($result)){{$result->display_order}}@else 0 @endif" placeholder="排序，数字越大越靠前">
            </div>
        </div>
       <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">文章置顶:</label>
            <div class="col-sm-9 col-xs-12">
                <label class="radio-inline">
                  <input type="radio" name="top" id="top1" value="1" @if(!empty($result))@if($result->top == 1) checked @endif @else checked @endif> 是
                </label>
                <label class="radio-inline">
                  <input type="radio" name="top" id="top2" value="0" @if(!empty($result))@if($result->top == 0) checked @endif @endif> 否
                </label>
             </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页推荐:</label>
            <div class="col-sm-9 col-xs-12">
                <label class="radio-inline">
                  <input type="radio" name="is_recommond" value="1" @if(!empty($result)) @if($result->is_recommond == 1) checked @endif @endif> 是
                </label>
                <label class="radio-inline">
                  <input type="radio" name="is_recommond"  value="0" @if(!empty($result)) @if($result->is_recommond == 0) checked @endif @else checked @endif> 否
                </label>
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">阅读数量:</label>
            <div class="col-sm-3 col-xs-12">
                  <input type="text" class="form-control" name="reading_num" id="reading_num" value="@if(!empty($result)) {{ count($result->exts)>0?$result->exts->reading_num:0}} @endif">
            </div>
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">推荐数量:</label>
            <div class="col-sm-3 col-xs-12">
                  <input type="text" class="form-control" name="recommond_num" id="recommond_num" value="@if(!empty($result)) {{ count($result->exts)>0?$result->exts->recommond_num:0}} @endif">
            </div>
        </div>
        <div class="form-group clearfix">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">开启考试：</label>
            <div class="col-sm-9 col-xs-12">
                <label class="radio-inline">
                  <input type="radio" name="test" id="test" value="0" onclick="examinations()" @if(!empty($result)&&($result->exam_id <= 0 || empty($result->exam_id) )) checked @else checked @endif > 不开启
                </label>
                <label class="radio-inline">
                  <input type="radio" name="test" id="test" value="1" onclick="examinations()" @if(!empty($result)&&$result->exam_id>0) checked @endif> 开启
                </label>
            </div>
        </div>
        <div class="form-group clearfix" id="examination">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">试卷编号：</label>
            <div class="col-sm-9 col-xs-12">
                <select name="exam_id" class="form-control">
                    @if(empty($exams))
                    <option value="0">暂无试卷，请先组卷</option>
                    @else
                    <option value="0">--请选择相关试卷--</option>
                    @foreach($exams as $ems)
                    <option value="{{ $ems->id }}" @if(!empty($result) && $ems->id == $result->exam_id)  selected @endif>{{ $ems->name }}</option>
                    @endforeach
                    @endif
                </select>
            </div>
        </div>
        <input type="hidden" name="template_id" value="goodnice">
        <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
        {!! csrf_field() !!}
        <input type="hidden" name="newsid" value="@if(!empty($result)){{ $result->id }}@endif">
        <div class="form-inline">
            <div class="form-group">
              <input type="hidden" name="status" value="1">
              <button type="button" class="btn btn-info" onclick="saveData('/admin/employ/index','newsForm')">
                    <i class="icon-ok bigger-110"></i>
                    Submit
              </button>  
            </div>
                    
            <div class="form-group col-xs-offset-1">
                <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
<!--
function examinations()
{
	if($('input[name=test]:checked').val() == 1)
	{
		$("#examination").show();
	}
	else
	{
		$("#examination").hide();
	}
}
$(function(){
	examinations();
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "queueSizeLimit"  :1,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/employimg',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	            var html="<div style='width:90px; height:60px;float:left;'>"
	            	+"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
	            	+"</div>"
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
	$('#employadd').click(function(){
		var html='<div class="form-group can-del clearfix">'
		   +'   <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>'
		   +'   <div class="col-sm-3 col-xs-12"><input type="text" class="form-control" name="content_title[]" value="" placeholder="左边标题"></div>'
		   +'   <div class="col-sm-6 col-xs-12"><textarea class="form-control content" name="content_content[]" placeholder="内容"></textarea></div>'
		   +'   <a class="delete-btn" onclick="deleteStep(this)"><i class="icon-remove"></i></a>'
		   +'</div>';
		$("#content_layout").append(html);
		editorInit();
	});
	
});
//-->
</script>
@endsection
